using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Firestarter.DB.Schema.UI;
using NUnit.Framework;

namespace Firestarter.DB.Schema.Test.UI
{
    [TestFixture]
    public class TestImageStackControl: TestBase
    {
        [Test]
        public void Test_AddObjectImages()
        {
            //---------------Set up test pack-------------------
            ImageStackControl imageStackControl = new ImageStackControl();
            Bitmap unselectedImage = Images._1_database_unselected;
            Bitmap selectedImage = Images._1_database_selected;
            //-------------Assert Preconditions -------------
            Assert.AreEqual(0, imageStackControl.Controls.Count);
            //---------------Execute Test ----------------------
            imageStackControl.AddObjectImages(new object(), unselectedImage, selectedImage);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, imageStackControl.Controls.Count);
            Assert.IsInstanceOf(typeof(PictureBox), imageStackControl.Controls[0]);
            PictureBox control = (PictureBox)imageStackControl.Controls[0];
            Assert.AreSame(unselectedImage, control.Image);
        }

        [Test]
        public void Test_AddObjectImages_SecondImage()
        {
            //---------------Set up test pack-------------------
            ImageStackControl imageStackControl = new ImageStackControl();
            Bitmap unselectedImage = Images._1_database_unselected;
            Bitmap selectedImage = Images._1_database_selected;
            imageStackControl.AddObjectImages(new object(), Images._2_selecttable_unselected, Images._2_selecttable_selected);
            //-------------Assert Preconditions -------------
            Assert.AreEqual(1, imageStackControl.Controls.Count);
            //---------------Execute Test ----------------------
            imageStackControl.AddObjectImages(new object(), unselectedImage, selectedImage);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, imageStackControl.Controls.Count);
            Assert.IsInstanceOf(typeof(PictureBox), imageStackControl.Controls[1]);
            PictureBox control = (PictureBox)imageStackControl.Controls[1];
            Assert.AreSame(unselectedImage, control.Image);
        }

        [Test]
        public void Test_SetCurrentObject()
        {
            //---------------Set up test pack-------------------
            ImageStackControl imageStackControl = new ImageStackControl();
            Bitmap unselectedImage = Images._1_database_unselected;
            Bitmap selectedImage = Images._1_database_selected;
            imageStackControl.AddObjectImages(new object(), Images._2_selecttable_unselected, Images._2_selecttable_selected);
            object myObject = new object();
            imageStackControl.AddObjectImages(myObject, unselectedImage, selectedImage);
            PictureBox control = (PictureBox)imageStackControl.Controls[1];
            //-------------Assert Preconditions -------------
            Assert.IsNull(imageStackControl.CurrentObject);
            Assert.AreSame(unselectedImage, control.Image);
            //---------------Execute Test ----------------------
            imageStackControl.SetCurrentObject(myObject);
            //---------------Test Result -----------------------
            Assert.AreSame(myObject, imageStackControl.CurrentObject);
            Assert.AreSame(selectedImage, control.Image);
        }

        [Test]
        public void Test_SetCurrentObject_ChangeToDifferent()
        {
            //---------------Set up test pack-------------------
            ImageStackControl imageStackControl = new ImageStackControl();
            object myObject1 = new object();
            Bitmap unselectedImage1 = Images._1_database_unselected;
            Bitmap selectedImage1 = Images._1_database_selected;
            imageStackControl.AddObjectImages(myObject1, unselectedImage1, selectedImage1);
            PictureBox pictureBox1 = (PictureBox)imageStackControl.Controls[0];
            object myObject2 = new object();
            Bitmap unselectedImage2 = Images._2_selecttable_unselected;
            Bitmap selectedImage2 = Images._2_selecttable_selected;
            imageStackControl.AddObjectImages(myObject2, unselectedImage2, selectedImage2);
            PictureBox pictureBox2 = (PictureBox)imageStackControl.Controls[1];
            imageStackControl.SetCurrentObject(myObject1);
            //-------------Assert Preconditions -------------
            Assert.AreSame(myObject1, imageStackControl.CurrentObject);
            Assert.AreSame(selectedImage1, pictureBox1.Image);
            Assert.AreSame(unselectedImage2, pictureBox2.Image);
            //---------------Execute Test ----------------------
            imageStackControl.SetCurrentObject(myObject2);
            //---------------Test Result -----------------------
            Assert.AreSame(myObject2, imageStackControl.CurrentObject);
            Assert.AreSame(unselectedImage1, pictureBox1.Image);
            Assert.AreSame(selectedImage2, pictureBox2.Image);
        }
    }
}
